<template>
    <div class="group">
        <li>团购</li>
        <el-card class="box-card">
            <div class="group-head">
                <div class="searchGroup">
                    <span>搜索:</span>
                    <el-input placeholder="请输入内容" v-model="keyword">
                        <el-button slot="append" icon="el-icon-search" @click="groupSearch" ></el-button>
                    </el-input>
                </div>
                <div class="streamState">
                        <span>状态: </span>
                        <el-select v-model="value" clearable placeholder="请选择" @change="changeState" >
                            <el-option label="已开团" value="已开团"></el-option>
                            <el-option label="未开团" value="未开团"></el-option>
                        </el-select>
                </div>
            </div>
            <el-table
                :data="groupList"
                stripe
                border >
                <el-table-column type="index" label="序号" ></el-table-column>
                <el-table-column label="图片" prop="img" ></el-table-column>
                <el-table-column label="楼盘名称" prop="buildname" ></el-table-column>
                <el-table-column label="楼盘地址" prop="address" ></el-table-column>
                <el-table-column label="发起人" prop="name" ></el-table-column>
                <el-table-column label="起始时间" prop="time" ></el-table-column>
                <el-table-column label="状态" prop="state" ></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" type="danger" @click="groupDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page.pageIndex"
                :page-sizes="[5, 10, 20, 30]"
                :page-size="page.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
export default {
  data () {
    return {
      groupList: [],
      page: {
        pageIndex: 1,
        pageSize: 5
      },
      total: 0,
      keyword: '',
      value: ''
    }
  },
  created () {
    this.getGroupList()
  },
  methods: {
    getGroupList () { // 分页
      this.$api.getGroupData(this.page).then(res => {
        console.log(res)
        if (res.data.code === 1) {
          this.groupList = res.data.data
          this.total = res.data.total
          this.$message.success('获取成功')
        }
      })
    },
    handleSizeChange (val) {
      this.page.pageSize = val
      this.getGroupList()
    },
    handleCurrentChange (val) {
      this.page.pageIndex = val
      this.getGroupList()
    },
    groupDelete (row) { // 删除
      this.$api.delGroup({ id: row.id }).then(res => {
        console.log(res)
        if (res.data.code === 1) {
          this.$message.success(res.data.message)
          this.getGroupList()
        }
      })
    },
    groupSearch () {
      this.$api.searchGroup({ keyword: this.keyword }).then(res => {
        if (res.data.code === 1) {
          this.groupList = res.data.data
          this.$message.success(res.data.message)
        }
      })
    },
    changeState () {
      this.$api.selectGroup({ state: this.value }).then(res => {
        if (res.data.code === 1) {
          this.groupList = res.data.data
          this.$message.success(res.data.message)
        }
      })
    }
  }
}
</script>

<style scoped>
.group{
    width: 100%;
    height: 100%;
}
.box-card{
    margin-top: 10px;
}
.group-head{
    display: flex;
    align-items: center;
}
.searchGroup{
    display: flex;
    align-items: center;
    margin-right: 10px;
}
.searchGroup span{
    width: 50px;
}
</style>
